{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e234d526-8b3d-4ba9-ab99-17f7e508ba0f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      "[0 0 0 0 0]\n",
      "[[1 1 1]\n",
      " [1 1 1]]\n",
      "[[99 99 99 99]\n",
      " [99 99 99 99]\n",
      " [99 99 99 99]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "a=np.array([[1,2,3],[4,5,6]])\n",
    "print(a)\n",
    "b=np.zeros(5,dtype='int')\n",
    "print(b)\n",
    "c=np.ones((2,3),dtype='int')\n",
    "print(c)\n",
    "d=np.full((3,4),99)\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e5e3b7bf-1a58-496b-a766-4741a94aecbb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4 5 6 7 8 9]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "x=np.arange(1,10,1)#起始值 终止值-不含 步长\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "19b48261-cc60-4a30-8b6a-397eb49dd78b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      "[1 2 3]\n",
      "[[2 4 6]\n",
      " [5 7 9]]\n",
      "[[0 0 0]\n",
      " [3 3 3]]\n",
      "[[1.  1.  1. ]\n",
      " [4.  2.5 2. ]]\n",
      "[[ 1  4  9]\n",
      " [ 4 10 18]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "a=np.array([[1,2,3],[4,5,6]])\n",
    "b=np.array([1,2,3])\n",
    "print(a)\n",
    "print(b)\n",
    "print(a+b)\n",
    "print(a-b)\n",
    "print(a/b)\n",
    "print(a*b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "82182ecf-ae85-4b8b-896d-14c4c1822e03",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4×3的整数数组：\n",
      " [[ 1  2  3]\n",
      " [ 4  5  6]\n",
      " [ 7  8  9]\n",
      " [10 11 12]]\n",
      "数组的ndim属性： 2\n",
      "数组的shape属性： (4, 3)\n",
      "数组的size属性： 12\n",
      "数组的dtype属性： int64\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\t\t\t\t\t\t\t#导入NumPy库\n",
    "#创建4×3的整数数组\n",
    "arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])\n",
    "print('4×3的整数数组：\\n', arr)\t\t\t\t#输出数组\n",
    "print('数组的ndim属性：', arr.ndim)\t\t#输出ndim属性\n",
    "print('数组的shape属性：', arr.shape)\t\t#输出shape属性\n",
    "print('数组的size属性：', arr.size)\t\t#输出size属性\n",
    "print('数组的dtype属性：', arr.dtype)\t\t#输出dtype属性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "57ffe86c-79ac-49eb-8071-1f23a2b4d848",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      "[[1 2]\n",
      " [3 4]\n",
      " [5 6]]\n",
      "[[1 2 3]\n",
      " [4 5 6]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "a=np.array([[1,2,3],[4,5,6]])\n",
    "print(a)\n",
    "b=a.reshape(3,2)#总个数不变\n",
    "print(b)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "6b72bc04-c3ce-482e-9806-a3bdea02bd2e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      "[[1 2]\n",
      " [3 4]]\n",
      "[[1 2]\n",
      " [3 4]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "a=np.array([[1,2,3],[4,5,6]])\n",
    "print(a)\n",
    "a.resize(2,2)#截断  补0\n",
    "print(a)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "3047e02b-c07c-4903-8a2c-bbd66b4036d3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "[2 3 4 5]\n",
      "[1 2 3 4 5]\n",
      "[2 3 4 5 6 7 8 9]\n",
      "[2 4]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "a=np.array([1,2,3,4,5,6,7,8,9])\n",
    "print(a[2])\n",
    "print(a[1:5])#索引 切片 a[1]~a[5]不含\n",
    "print(a[:5])\n",
    "print(a[1:])\n",
    "print(a[1:5:2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "55949691-8596-4a47-8e78-f7a2e3e84a44",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
